using System;
using SrBBSPro.Entities;
using SrBBSPro.BaseClasses;
using System.Collections.Generic;
using System.Text;

namespace SrBBSPro.Services
{
    public class ProjectService : BaseService<Project, long> 
    {
        public List<Project> GetProjectList(string depart,string name, out int count,int page)
        {
            var sql = new StringBuilder();
            sql.Append("select * from Project where 1 = 1");
            if (!string.IsNullOrEmpty(depart))
            {
                sql.Append(" and depart=@0 ");
            }
            if (!string.IsNullOrEmpty(name))
            {
                sql.Append(" and name =@1 ");
            }
            var li = DbBase.Fetch<Project>(sql.ToString(), depart, name);
            return GetLimitList(li, out count, page);
        }

        public List<string> GetProjectNames(string depart)
           =>DbBase.Fetch<string>("select name from Project where depart=@0 ", depart);

        public List<Project> GetMyProject(string StaffNo)
            => DbBase.Fetch<Project>("select * from Project where Id In (select Id from " +
                "ProMember where no=@0) AND EndDate >GETDATE()", StaffNo);               
    }
}
